blob: 566dcd90a3484df36dfdd203af4578709ec22511 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import { getAssignmentAndCemetaryById } from "$lib/server/assignments";
import type { PageServerLoad } from "./$types";
import { error, redirect } from "@sveltejs/kit";
export const load = (async ({ params, url, locals }) => {
if (!locals.user) {
redirect(303, `/login?redirectTo=${encodeURIComponent(url.toString())}`);
}
const { assignment, cemetaryPlot } = await getAssignmentAndCemetaryById(
locals.dbConn,
+params.assignmentId,
);
if (!assignment) {
return error(404, `Cemetary plot with id ${params.assignmentId} not found`);
}
console.debug("Found assignment: ", assignment);
if (assignment.gardenerId !== locals.user.id) {
return error(403, "This assignment isn't for you!");
}
return {
user: locals.user,
assignment,
cemetaryPlot,
};
}) satisfies PageServerLoad;
|